home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 117 / MacAddict 117.dmg / Software / Internet & Communication / Snak 5.1 (shareware).dmg / Snak.app / Contents / Resources / Scripts / pp-dcc.irc < prev    next >
Text File  |  2005-08-04  |  23KB  |  908 lines

  1. # ########################################################################## #
  2. #                      PurePak - The sequel to TextBox                       #
  3. #                          A -+ TEXT +- production                           #
  4. # ########################################################################## #
  5. # Author: Crypt Keeper [ckeeper@axiom.access.one.net] (CKeeper on IRC)
  6. # Version 2.07
  7. #
  8. # This script requires at least ircII2.2.9 (Unix) or a fully ircII compatible
  9. # client.  It has only been tested under Unix with ircII2.2.9 and ircII2.8.2.
  10. #
  11. # If you edit this file, you must edit it with a Unix text editor or use
  12. # utilities like dos2unix/unix2dos to convert it to DOS to edit and then
  13. # back to Unix.  If it is edited in a DOS text editor it will be corrupted.
  14. #
  15. # PurePak version 2.07 IRC script
  16. # Copyright (C) 1995
  17. #
  18. # This program is free software; you can redistribute it and/or modify
  19. # it under the terms of the GNU General Public License as published by
  20. # the Free Software Foundation; either version 1, or (at your option)
  21. # any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. # GNU General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU General Public License
  29. # along with this program; if not, write to the Free Software
  30. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. # ########################################################################## #
  32.  
  33. # Modified for Snak by Kent Sorensen. 
  34. # Removed many unnecessary functions, and added functions in Snak to make it work well with spaces in the filenames
  35. # Special Snak functions: $filesize for a full path, or tab delimited list and $filename which returns the flename from a path
  36. # Also $listitem, and $listitemcount. The input command returns a tab delimeted list of files. 
  37. # Also $dccitem, $dccsendcount, and $dccreceivecount()
  38. # Made numerous changes to support spaces in file names
  39. # Removed the old purepak code that tried to find the filesize for of an item by DCC'ing it to yourself and extracting the size from the DCC request. Yuck. 
  40. # Added a number of comments to help people read the script more easily
  41.  
  42. # DCC autoaccept functions are much better done from inside Snak itself with the Actions list. They have been removed.
  43. # use new Snak function $dccsendcount() instead of DCC.NSENDING
  44.  
  45. # changed message format and available commands to match iroffer more closely
  46. # removed lspack
  47.  
  48. EVAL ^if (!(PPVERS)) {/echo *** This is not a stand-alone script, it must be loaded after purepak.irc;//exit}
  49.  
  50. # DCC fileserver/manager script
  51. @ PP.DCC = 1
  52.  
  53.  
  54. # ----------------------------------------------------------------------------
  55. # DCC alias
  56. # ----------------------------------------------------------------------------
  57.  
  58. alias xdcc {
  59.     /dcc $*
  60. }
  61.  
  62. alias dcc {
  63.     if ([$0])
  64.     {
  65.         if (match($0 SEND GET RAW TALK CHAT OFFER DOFFER LIST NOTICE LOAD SAVE CLOSE LIMIT RENAME TMSG NOTE SERVER TIMEOUT QUEUEING PUBLIST ADVERTISE ADINTERVAL CHANNEL))
  66.         {
  67.             if (match($0 RAW TALK RENAME TMSG SEND CHAT)) 
  68.             {
  69.                 //dcc $*
  70.             }
  71.             if (match($0 CLOSE OFFER DOFFER LIST NOTICE LOAD SAVE LIMIT NOTE SERVER TIMEOUT QUEUEING PUBLIST ADVERTISE ADINTERVAL CHANNEL)) 
  72.             {
  73.                 /dcc.ucmd.$0 $1-
  74.             }
  75.         } 
  76.         {
  77.             /echo *** Unrecognized DCC command, type /pphelp dcc
  78.         }
  79.     }
  80. }
  81.  
  82. EVAL ^if (!PP.SET.DCCLIMIT) {@ PP.SET.DCCLIMIT = [-1]}
  83. EVAL ^if (!PP.SET.DCCSERVER) {@ PP.SET.DCCSERVER = [ON]}
  84. EVAL ^if (!PP.SET.DCCTIMEOUT) {@ PP.SET.DCCTIMEOUT = 90}
  85. EVAL ^if (!PP.SET.DCCPUBLIST) {@ PP.SET.DCCPUBLIST = [ON]}
  86. EVAL ^if (!PP.SET.DCCQUEUEING) {@ PP.SET.DCCQUEUEING = [ON]}
  87.  
  88. # to advertise do "/dcc advertise ON", do "/dcc adinterval number" to control the interval. default is 5
  89. EVAL ^if (!PP.SET.DCCADVERTISE) {@ PP.SET.DCCADVERTISE = [OFF]}
  90. EVAL ^if (!PP.SET.DCCADINTERVAL) {@ PP.SET.DCCADINTERVAL = 5}
  91.  
  92. @ PP.DELAYUNTILADVERTISEMENT = PP.SET.DCCADINTERVAL
  93.  
  94.  
  95. # ----------------------------------------------------------------------------
  96. # /dcc functions
  97. # ----------------------------------------------------------------------------
  98.  
  99. # /dcc queueing
  100. alias dcc.ucmd.queueing {
  101.     if (match($0 ON OFF)) 
  102.     {
  103.         @ PP.SET.DCCQUEUEING = toupper($0)
  104.     }
  105.     echo *** Queueing of send requests if all slots are full is now ${PP.SET.DCCQUEUEING}
  106. }
  107.  
  108. # /file server
  109. alias dcc.ucmd.server {
  110.     if (match($0 ON OFF)) 
  111.     {
  112.         @ PP.SET.DCCSERVER = toupper($0)
  113.     }
  114.     echo *** DCC file server is now ${PP.SET.DCCSERVER}
  115. }
  116.  
  117. # /dcc advertise
  118. alias dcc.ucmd.advertise {
  119.     if (match($0 ON OFF)) 
  120.     {
  121.         @ PP.SET.DCCADVERTISE = toupper($0)
  122.     }
  123.     echo *** DCC advertisement is now ${PP.SET.DCCADVERTISE}
  124.     
  125.     if (PP.SET.DCCADVERTISE == [ON])
  126.     {
  127.         if (PP.SET.DCCADINTERVAL == [-1])
  128.         {
  129.             @ PP.SET.DCCADINTERVAL = 5
  130.         }
  131.         /echo *** DCC advertisement interval is now ${PP.SET.DCCADINTERVAL} minutes
  132.         
  133.         @ PP.DELAYUNTILADVERTISEMENT = PP.SET.DCCADINTERVAL
  134.     }
  135. }
  136.  
  137.  
  138. # /dcc adinterval
  139. # Set the number of minutes between each add
  140. alias dcc.ucmd.adinterval {
  141.     if ([$0])
  142.     {
  143.         if (([$0] == [NONE])||([$0] == [OFF])) 
  144.         {
  145.             @ PP.SET.DCCADINTERVAL = [-1]
  146.         }
  147.         {
  148.             if (!isalpha($0))
  149.             {
  150.                 @ PP.SET.DCCADINTERVAL = [$0]
  151.                 @ PP.DELAYUNTILADVERTISEMENT = PP.SET.DCCADINTERVAL
  152.             }
  153.             {
  154.                 /echo *** Must be a numerical value
  155.             }
  156.         }
  157.     }
  158.     if (PP.SET.DCCADINTERVAL == [-1])
  159.     {
  160.         /echo *** DCC advertisement is now OFF
  161.     }
  162.     {    
  163.         /echo *** DCC advertisement interval is now ${PP.SET.DCCADINTERVAL} minutes
  164.     }
  165. }
  166.  
  167.  
  168. # /dcc channel
  169. # Set the channel in which to advertize
  170. alias dcc.ucmd.channel {
  171.     if ([$0])
  172.     {
  173.         @ PP.SET.DCC_CHANNEL = [$0]
  174.         /echo *** DCC channel is now ${PP.SET.DCC_CHANNEL} 
  175.     }
  176.     {    
  177.         @ PP.SET.DCC_CHANNEL = [$]
  178.         /echo *** DCC channel is now empty
  179.     }
  180. }
  181.  
  182.  
  183. # /dcc publist
  184. alias dcc.ucmd.publist {
  185.     if (match($0 ON OFF)) 
  186.     {
  187.         @ PP.SET.DCCPUBLIST = toupper($0)
  188.     }
  189.     echo *** Allow public CTCP XDCC LISTs is now ${PP.SET.DCCPUBLIST}
  190. }
  191.  
  192. # /dcc note
  193. alias dcc.ucmd.note {
  194.     if ([$0]) 
  195.     {
  196.         ^if ([$0] != [-]) 
  197.         {
  198.             @ DCC.NOTE = [$*]
  199.         }
  200.         {
  201.             ^assign -DCC.NOTE
  202.         }
  203.     }
  204.     if (DCC.NOTE) 
  205.     {
  206.         /echo *** DCC offer list note: $DCC.NOTE
  207.     }
  208.     {
  209.         /echo *** No DCC offer list note set
  210.     }
  211. }
  212.  
  213.  
  214.  
  215. # ** 12 packs **  0 of 10 slots open, Queue: 6/15, Min: 30.0KB/s, Max: 250.0KB/s, Record: 618.5KB/s
  216.  
  217. # /dcc notice
  218. # send advertisement to the current channel. List available slots and pack information.
  219. alias dcc.ucmd.notice {
  220.  
  221.     if (PP.SET.DCC_CHANNEL)
  222.     {
  223.         if (dcc.havepacks()){
  224.             if (dcc.havepacks() == 1)
  225.             {
  226.                 if ([$PP.SET.DCCLIMIT] != -1) 
  227.                 {
  228.                     EVAL @ SEND_MSG = [** 1 pack ** ${PP.SET.DCCLIMIT - dccsendcount()} slots available]
  229.                 }
  230.                 {
  231.                     EVAL @ SEND_MSG = [** 1 pack ** slots available]
  232.                 }
  233.             } 
  234.             { 
  235.                 if ([$PP.SET.DCCLIMIT] != -1) 
  236.                 {
  237.                     EVAL @ SEND_MSG = [** ${dcc.havepacks()} packs ** ${PP.SET.DCCLIMIT - dccsendcount()} slots available]
  238.                 }
  239.                 {    
  240.                     EVAL @ SEND_MSG = [** ${dcc.havepacks()} packs ** slots available]
  241.                 }
  242.             }
  243.             
  244.             ^pp.listmsg PRIVMSG $PP.SET.DCC_CHANNEL
  245.             echo $SEND_MSG
  246.             
  247.             EVAL @ SEND_MSG = [** To request a file type "/msg $N xdcc send #n"]
  248.             ^pp.listmsg PRIVMSG $PP.SET.DCC_CHANNEL
  249.             echo $SEND_MSG
  250.  
  251.             dcc.dolist 1 ^quote PRIVMSG $PP.SET.DCC_CHANNEL :
  252.             dcc.dolist 1 ^echo 
  253.  
  254.             ^assign -SEND_MSG
  255.         } 
  256.         {
  257.             /echo *** You aren't offering any packs
  258.         }
  259.     }
  260.     {
  261.         echo *** The DCC Channel has not been set. Use /DCC channel <#channelname> to set it.
  262.     }
  263. }
  264. # /dcc offer
  265. # create a pack of files to offer. A pack can contain multiple individual files. Each file is sent by itself.
  266. # It will first display a file browser where you can select the files to include.
  267. # Then you will be asked to provide the description of the pack.
  268.  
  269. # Mac file paths can contain spaces, so input -files return a list that is separated with tabs
  270. # Use "listitem" to split it instead of "word"
  271. # Snak adaptation 1.10. remove reference to the multiple file support in a pack
  272. # New Snak function filesize() gets the filesize directly.  Store the size of the file(s) in the pack in variable.
  273.  
  274. alias dcc.ucmd.offer {
  275.     ^input -files "Choose file to offer: " if (1) {
  276.         if ([$0])
  277.         {
  278. # the string is tab delimited but there may be spaces in the filenames. use listitem and listitemcount.
  279.             @ DCCFILS = [$*]
  280.             
  281.             ^input "Enter a description for this pack: " if (1) {
  282.                 if ([$0])
  283.                 {
  284.                     @ IDX = 1
  285. #iterate until finding an unused index
  286.                     while (DCCPACKS.FILES[$IDX]) {@ IDX = IDX + 1}
  287.                     @ DCCPACKS.FILES[$IDX] = DCCFILS
  288.                     
  289. # $DCCFILS is actually a tab delimited list but filesize can handle that
  290.                     @ DCCPACKS.SIZE[$IDX] = filesize($DCCFILS)
  291.                     
  292.                     @ DCCPACKS.DESC[$IDX] = [$*]
  293.                     @ DCCPACKS.STATS[$IDX] = [0]
  294.                     echo *** Pack #$IDX added with files: ${DCCFILS}
  295.                     ^assign -IDX
  296.                     ^assign -DCCFILS
  297.                 }
  298.                 {
  299.                     ^assign -IDX
  300.                     ^assign -DCCFILS
  301.                     echo *** You must enter a description
  302.                 }
  303.             }
  304.         } 
  305.         {
  306.             /echo *** No files in pack!
  307.         }
  308.     }
  309. }
  310.  
  311.  
  312.  
  313. # /dcc doffer
  314. # Delete a package. Delete only one at a time.
  315. alias dcc.ucmd.doffer {
  316.     ^input "Enter pack number(s) to remove: " if (1) {
  317.         if ([$0])
  318.         {
  319.             @ AA = 0
  320.             while (word($AA $*))
  321.             {
  322. # iterate over the words in the input, and delete the corresponding packs
  323.                 if (DCCPACKS.FILES[$word($AA $*)])
  324.                 {
  325.                     ^assign -DCCPACKS.FILES[$word($AA $*)]
  326.                     ^assign -DCCPACKS.SIZE[$word($AA $*)]
  327.                     ^assign -DCCPACKS.DESC[$word($AA $*)]
  328.                     ^assign -DCCPACKS.STATS[$word($AA $*)]
  329.                     @ CTR = word($AA $*) + 1
  330. # copy the packs following this one down one slot. THIS WILL NOT WORK RIGHT if you delete more than one pack
  331. # You provide indexes of the paths to delete, and this changes the indexes...
  332.                     while (DCCPACKS.FILES[$CTR])
  333.                     {
  334.                         @ DCCPACKS.FILES[${CTR-1}] = DCCPACKS.FILES[$CTR]
  335.                         @ DCCPACKS.SIZE[${CTR-1}] = DCCPACKS.SIZE[$CTR]
  336.                         @ DCCPACKS.DESC[${CTR-1}] = DCCPACKS.DESC[$CTR]
  337.                         @ DCCPACKS.STATS[${CTR-1}] = DCCPACKS.STATS[$CTR]
  338.                         if (!(DCCPACKS.FILES[${CTR+1}]))
  339.                         {
  340.                             ^assign -DCCPACKS.FILES[$CTR]
  341.                             ^assign -DCCPACKS.SIZE[$CTR]
  342.                             ^assign -DCCPACKS.DESC[$CTR]
  343.                             ^assign -DCCPACKS.STATS[$CTR]
  344.                         }
  345.                         @ CTR = CTR + 1
  346.                     }
  347.                     echo *** Pack #$word($AA $*) removed
  348.                 } {/echo *** There is no pack #$word($AA $*)}
  349.                 @ AA = AA + 1
  350.             }
  351.             ^assign -CTR
  352.         }
  353.     }
  354. }
  355.  
  356. # /dcc list
  357. # Display available slots and pack information in response to XDCC list
  358. alias dcc.ucmd.list {
  359.     if (dcc.havepacks())
  360.     {
  361.         if (PP.SET.DCCLIMIT > 0) 
  362.         {
  363.             /echo *** Files offered: [${PP.SET.DCCLIMIT - dccsendcount()} slots available]
  364.         }
  365.         {
  366.             /echo *** Files offered:
  367.         }
  368.         dcc.dolist 1 echo ***
  369.     } 
  370.     {
  371.         /echo *** You have no files offered
  372.     }
  373. }
  374.  
  375. # /dcc save
  376. # The package file is saved in the PurePak directory in the home directory
  377. # The script takes an optional parameter. If absent, the package data will be saved in a file called purepak.dcc
  378. # Snak adaptation 1.10 save the DCCPACKS.FILES variable unchanged
  379. # Snak adaptation 1.11 use the new delete, open, close and write functions
  380. alias dcc.ucmd.save {
  381.     if ([$0])
  382.     {
  383.         @ LF = [${HOME}/Purepak/$0]
  384.         @res = delete($LF)
  385.  
  386.         @ FHANDLE = open($LF w)
  387.         if (FHANDLE > 0) 
  388.         {
  389.             @res = write( $FHANDLE # PurePak DCC module offer file, written $stime($time()))
  390.             foreach DCCPACKS.FILES AA {
  391.  
  392.                 @res = write( $FHANDLE ^dcc.addpack $encode($DCCPACKS.FILES[$AA]) $encode($DCCPACKS.DESC[$AA]))
  393.             }
  394.  
  395.             if (DCC.NOTE) 
  396.             {
  397.                 @res = write( $FHANDLE ^dcc.ucmd.note $DCC.NOTE)
  398.             }
  399.             
  400.             @res = close($FHANDLE)
  401.  
  402.             echo *** Current pack data written to $LF
  403.         }
  404.         {
  405.             /echo *** Could not open $LF
  406.         }
  407.  
  408.         ^assign -LF
  409.         ^assign -FHANDLE
  410.     } 
  411.     {
  412.         /dcc.ucmd.save purepak.dcc
  413.     }
  414. }
  415.  
  416.  
  417. # /dcc load
  418. # Load a package data file into memory. The package file must be located in the Purepak directory
  419. # The script takes an optional filename parameter. If it is missing purepak.dcc will be used
  420. alias dcc.ucmd.load {
  421.     ^if ([$0]) 
  422.     {
  423.         /echo *** reading pack data from ${HOME}/Purepak/$0
  424.         //load -p ${HOME}/Purepak/$0
  425.     }
  426.     {
  427.         /echo *** reading pack data from ${HOME}/Purepak/purepak.dcc
  428.         //load -p ${HOME}/Purepak/purepak.dcc
  429.     }
  430. }
  431.  
  432.  
  433. # /dcc limit
  434. # set the number of allowed simultaneous DCC sends. Set to -1 to allow unlimited number of DCC sends.
  435. alias dcc.ucmd.limit {
  436.     if ([$0])
  437.     {
  438.         if (([$0] == [NONE])||([$0] == [OFF])) 
  439.         {
  440.             @ PP.SET.DCCLIMIT = [-1]
  441.         }
  442.         {
  443.             if (!isalpha($0)) 
  444.             {
  445.                 @ PP.SET.DCCLIMIT = [$0]
  446.             }
  447.             {    
  448.                 /echo *** Must be a numerical value
  449.             }
  450.         }
  451.     }
  452.     if (PP.SET.DCCLIMIT == [-1]) 
  453.     {
  454.         /echo *** DCC autosend file limit is now UNLIMITED
  455.     }
  456.     {
  457.         /echo *** DCC autosend file limit is now ${PP.SET.DCCLIMIT}
  458.     }
  459. }
  460.  
  461.  
  462. # /dcc timeout
  463. # Set the timeout amount before a waiting DCC send is closed
  464. alias dcc.ucmd.timeout {
  465.     if ([$0])
  466.     {
  467.         if (([$0] == [NONE])||([$0] == [OFF])) 
  468.         {
  469.             @ PP.SET.DCCTIMEOUT = [-1]
  470.         }
  471.         {
  472.             if (!isalpha($0))
  473.             {
  474.                 @ PP.SET.DCCTIMEOUT = [$0]
  475.             }
  476.             {
  477.                 /echo *** Must be a numerical value
  478.             }
  479.         }
  480.     }
  481.     if (PP.SET.DCCTIMEOUT == [-1])
  482.     {
  483.         /echo *** DCC autosend timeout is now UNLIMITED
  484.     }
  485.     {    
  486.         /echo *** DCC autosend timeout is now ${PP.SET.DCCTIMEOUT}
  487.     }
  488. }
  489.  
  490.  
  491.  
  492. # /dcc close
  493. # Close a DCC send 
  494. alias dcc.ucmd.close {
  495.     if (match($0 RAW TALK CHAT RAW_LISTEN RAW_LIS)) 
  496.     {
  497.         //dcc close $*
  498.     }
  499.     {
  500.         @ AA = 0
  501.         if ([$0] == [SEND])
  502.         {
  503.             if ([$1])
  504.             {
  505.                 if ([$2]) 
  506.                 {
  507.                     //dcc close $*
  508.                 }
  509.                 {
  510.                     EVAL ^repeatcmd 30 //^dcc close send $1
  511.                     echo *** All DCC SENDs to $1 closed
  512.                 }
  513.             } 
  514.             {
  515.                 /echo *** /dcc close send <nick> [<file>]
  516.             }
  517.             @ AA = 1
  518.         }
  519.  
  520.         if (!AA) 
  521.         {
  522.             /echo *** /dcc close <type> <nick> [<arguments>]
  523.         }
  524.     }
  525. }
  526.  
  527. # ----------------------------------------------------------------------------
  528. # ON hooks and internal procedures
  529. # ----------------------------------------------------------------------------
  530.  
  531. # We use a raw_irc for on msg to prevent a beep if BEEP_ON_MSG is set
  532. on ^raw_irc "% PRIVMSG % :XDCC *" {
  533.     if (!ischannel($2))
  534.     {
  535.         if (PP.SET.DCCSERVER == [ON]) 
  536.         {
  537.             /dcc.msg $nickonly($0) $N $mid(${index(! $0)+1} 1000 $0) $4-
  538.         }
  539.     }
  540.     {
  541.         if ([$2] == C) 
  542.         {
  543.             /xecho -LEVEL PUBLIC <$nickonly($0)> $strip(: $3) $4-
  544.         }
  545.         {
  546.             /xecho -LEVEL PUBLIC <$nickonly($0):$2> $strip(: $3) $4-
  547.         }
  548.     }
  549. }
  550.  
  551.  
  552. on ^ctcp "% % XDCC *" {
  553.     ^if (PP.SET.DCCSERVER == [ON]) 
  554.     {
  555.         /dcc.msg $0 $1 $USERHOST() $3-
  556.     }
  557. }
  558.  
  559. alias dcc.msg {
  560.     if (right(10 $2) != LASTDCCER)
  561.     {
  562.         if (ischannel($1))
  563.         {
  564.             if (match($3 SEND LIST HELP VERSION))
  565.             {
  566.                 if ([$3] == [LIST])
  567.                 {
  568.                     if (PP.SET.DCCPUBLIST == [ON])
  569.                     {
  570.                         if (dcc.havepacks()) 
  571.                         {
  572.                             /dcc.msg $0 $N $2-
  573.                         }
  574.                     } 
  575.                     {
  576.                         /echo *** $0 request for DCC LIST to everyone in $1 ignored
  577.                     }
  578.                 }
  579.                 {
  580.                     echo *** $0 request for DCC $toupper($3) to everyone in $1 ignored\; only LIST is allowed globally
  581.                     //^notice $0 Only DCC LISTs are allowed globally
  582.                 }
  583.             }
  584.             {
  585.                 echo *** Invalid file server command from $0 to $1
  586.                 //^notice $0 Unknown file server command\; type /msg $N XDCC HELP
  587.             }
  588.         }
  589.         {
  590.             if (match($3 SEND LIST HELP VERSION)) 
  591.             {
  592.                 /dcc.mcmd.$3 $0 $2 $4-
  593.             }
  594.             {
  595.                 echo *** Invalid file server command from $0
  596.                 //^notice $0 Unknown file server command\; type /msg $N XDCC HELP
  597.             }
  598.         }
  599.     }
  600.     if (!LASTDCCER) 
  601.     {
  602.         ^timer 3 ^assign -LASTDCCER
  603.     }
  604.     @ LASTDCCER = right(10 $2)
  605. }
  606.  
  607. # Executed when a saved pack file loads
  608. # FILZ is a tab delimited list so use listitem
  609. alias dcc.addpack {
  610.     @ FILZ = decode($0)
  611.         
  612.     @ AA = 0
  613.     while (listitem($AA $FILZ))
  614.     {
  615.         if (!fileexists($listitem($AA $FILZ)))
  616.         {
  617.             echo *** LOAD: file $listitem($AA $FILZ) does not exist, removed from pack
  618.  
  619.             @FILZ = listitemdelete($AA $FILZ)
  620.         }
  621.         {    
  622. # if we deleted the item from the list, the index should not be incremented
  623.             @ AA = AA + 1
  624.         }
  625.     }
  626.     
  627.     if ([$#FILZ] > 0)
  628.     {
  629.         @ IDX = 1
  630. # find next available index
  631.         while (DCCPACKS.FILES[$IDX]) {@ IDX = IDX + 1}
  632.         @ DCCPACKS.FILES[$IDX] = FILZ
  633.         @ DCCPACKS.SIZE[$IDX] = filesize($FILZ)
  634.         @ DCCPACKS.DESC[$IDX] = decode($1)
  635.         @ DCCPACKS.STATS[$IDX] = [0]
  636.         echo *** Pack #$IDX loaded with files: $FILZ
  637.         echo ***   - Description: $decode($1)
  638.         ^assign -IDX
  639.     } {/echo *** Pack not restored: no files}
  640.     ^assign -FILZ
  641. }
  642.  
  643. # /dcc.dolist <show filenames too?> <command to do list>
  644. alias dcc.dolist {
  645.     @ MAXV = 0
  646.     foreach DCCPACKS.FILES AA 
  647.     {
  648.         ^if (AA > MAXV) 
  649.         {
  650.             @ MAXV = AA
  651.         }
  652.     }
  653.     
  654.     @ AA = 0
  655.     while (AA <= MAXV)
  656.     {
  657.         if (DCCPACKS.FILES[$AA]) 
  658.         {
  659.             $1- #${AA} $DCCPACKS.STATS[$AA]x [$formatnumber($DCCPACKS.SIZE[$AA])] $DCCPACKS.DESC[$AA] 
  660.             
  661. # You don't want to display the actual file names and full paths
  662. #            EVAL $1-    +  [$DCCPACKS.SIZE[$AA] bytes]
  663. #            if ([$0]) 
  664. #            {
  665. #                $1- #${AA} - Files: $FILS
  666. #            }
  667.         }
  668.         @ AA = AA + 1
  669.     }
  670.     ^assign -FILS
  671.     ^assign -MAXV
  672.     if (DCC.NOTE) 
  673.     {
  674.         $1- * Note: $DCC.NOTE
  675.     }
  676. }
  677.  
  678. # Returns number of packages offered
  679. alias dcc.havepacks {
  680.     @ FUNCTION_RETURN = 0
  681.     foreach DCCPACKS.FILES BsB {}
  682.     @ FUNCTION_RETURN = [$BsB]
  683.     ^assign -BsB
  684. }
  685.  
  686. # Queues a send for the timeout timer
  687. # $0 nick of receiver
  688. # $1 time of start of sending
  689. # $2 filepath - MAY CONTAIN SPACES
  690. alias dcc.queuetimeout {
  691.     @ SENDID = rand(99999)
  692. # maintain two parallel variables per transmission. It is a mess to encode the path and the timeout in one since there can be spaces
  693.     @ DCC.SENDTIME[$encode($0)][$SENDID] = [$1]
  694.     @ DCC.SENDFILE[$encode($0)][$SENDID] = [$2-]
  695.     ^assign -SENDID
  696. }
  697.  
  698. # Checks for DCC's that have timed out and runs queued DCC's
  699. on #^timer 22 * {
  700.     if (PP.SET.DCCTIMEOUT != [-1])
  701.     {
  702.         foreach DCC.SENDTIME AA {
  703.             EVAL ^foreach DCC.SENDTIME.$AA BB {
  704.             
  705.                 echo time since queueing [${time() - DCC.SENDTIME[$AA][$BB]}]
  706.             
  707.                 if ([${time() - DCC.SENDTIME[$AA][$BB]}] >= PP.SET.DCCTIMEOUT)
  708.                 {
  709. # dispose of the DCC send
  710.                     //^dcc close send $decode($AA) $filename($DCC.SENDFILE[$AA][$BB])
  711.  
  712.                     echo *** DCC SEND $filename($DCC.SENDFILE[$AA][$BB]) to $decode($AA) timed out
  713.                     //^notice $decode($AA) DCC SEND $filename($DCC.SENDFILE[$AA][$BB]) timed out
  714.                     
  715.                     ^assign -DCC.SENDTIME[$AA][$BB]
  716.                     ^assign -DCC.SENDFILE[$AA][$BB]
  717.                 }
  718.             }
  719.         }
  720.     }
  721.     if (PP.SET.DCCLIMIT != [-1])
  722.     {
  723.         while (dcc.gotqueue())
  724.         {
  725.             @ BB = 0
  726.             @ OLDESTQUEUE = 0
  727.             foreach DCC.SENDQUEUE AA {
  728.                 if ([${time() - AA}] > BB)
  729.                 {
  730.                     @ BB = time() - AA
  731.                     @ OLDESTQUEUE = AA
  732.                 }
  733.             }
  734.             echo *** Sending queued pack #$strip(# $word(2 $DCC.SENDQUEUE[$OLDESTQUEUE])) to $word(0 $DCC.SENDQUEUE[$OLDESTQUEUE])
  735.             ^alias echo {}
  736.             ^dcc.mcmd.send $DCC.SENDQUEUE[$OLDESTQUEUE]
  737.             ^alias -echo
  738.             ^assign -DCC.SENDQUEUE[$OLDESTQUEUE]
  739.         }
  740.         ^assign -OLDESTQUEUE
  741.     }
  742.     {
  743.         foreach DCC.SENDQUEUE AA {
  744.             echo *** Sending queued pack #$strip(# $word(2 $DCC.SENDQUEUE[$AA])) to $word(0 $DCC.SENDQUEUE[$AA])
  745.             ^alias echo {}
  746.             ^dcc.mcmd.send $DCC.SENDQUEUE[$AA]
  747.             ^alias -echo
  748.             ^assign -DCC.SENDQUEUE[$AA]
  749.         }
  750.     }
  751.     ^assign -BB
  752. }
  753.  
  754. # periodically displays the advertisement if turned on
  755. # a timer is called every minute
  756. on #^timer 23 * {
  757.  
  758.     if (PP.SET.DCCSERVER == [ON])
  759.     {
  760.         if (PP.SET.DCCADVERTISE == [ON])
  761.         {
  762.             @ PP.DELAYUNTILADVERTISEMENT = PP.DELAYUNTILADVERTISEMENT - 1
  763.             
  764.             if (PP.DELAYUNTILADVERTISEMENT == [0])
  765.             {
  766. # it is time to do the advertisement
  767.                 dcc.ucmd.notice
  768.  
  769.                 @ PP.DELAYUNTILADVERTISEMENT = PP.SET.DCCADINTERVAL
  770.             }
  771.         }
  772.     }
  773. }
  774.  
  775. # Returns true if files are queued and there are slots available
  776. alias dcc.gotqueue {
  777.     @ FUNCTION_RETURN = 0
  778.     foreach DCC.SENDQUEUE AB {^if (dccsendcount() < PP.SET.DCCLIMIT) {@ FUNCTION_RETURN = 1}}
  779.     ^assign -AB
  780. }
  781.  
  782. # Removes timeouts when sends are initiated
  783. # $0 is SEND/GET $1 is nick, $2- filename
  784. on dcc_connect *
  785. {
  786.     foreach DCC.SENDTIME AA {
  787.         ^if (decode($AA) == [$1]) 
  788.         {
  789.             ^EVAL ^foreach DCC.SENDTIME.$AA BB 
  790.             {
  791. # since there may be spaces in the filename, encode before comparing            
  792.                 if ([$encode($filename($DCC.SENDFILE[$AA][$BB]))] == [$encode($2-)])
  793.                 {
  794.                     ^assign -DCC.SENDTIME[$AA][$BB]
  795.                     ^assign -DCC.SENDFILE[$AA][$BB]
  796.                 }
  797.             }
  798.         }
  799.     }
  800.     ^assign -BB
  801. }
  802.  
  803. # ----------------------------------------------------------------------------
  804. # User /msg command functions
  805. # ----------------------------------------------------------------------------
  806.  
  807. alias dcc.mcmd.version {
  808.     if (index(Y $PP.SET) == [-1])
  809.     {
  810.         //^notice $0 PurePak version $PPVERS DCC module
  811.         echo *** $0 [$strip( $1)] requested your version
  812.     }
  813. }
  814.  
  815. alias dcc.mcmd.help {
  816.     //^notice $0 Available file server commands:
  817.     //^notice $0 HELP, LIST, SEND <#pack>, <#pack>, VERSION
  818.     echo *** $0 [$strip( $1)] requested file server help
  819. }
  820.  
  821. alias dcc.mcmd.list {
  822.     if (dcc.havepacks())
  823.     {
  824.         //^notice $0 Files available: Type /msg $N XDCC SEND #N to get pack #N
  825.         if (PP.SET.DCCLIMIT > 0) 
  826.         {
  827.             //^notice $0 [${PP.SET.DCCLIMIT - dccsendcount()} slots available]
  828.         }
  829.         EVAL ^dcc.dolist 0 //^notice $0
  830.         echo *** $0 [$strip( $1)] requested a list of files offered
  831.     }
  832.     {
  833.         //^notice $0 No files offered
  834.     }
  835. }
  836.  
  837. # snak adaptation 1.5 use listitem and don't check for /
  838. # snak adaptation 1.10 use DCCPACKS.SIZE instead of packsize
  839. alias dcc.mcmd.send {
  840.  
  841.     if (DCCPACKS.FILES[$strip(# $2)])
  842.     {
  843.         if ((dccsendcount() >= PP.SET.DCCLIMIT)&&(PP.SET.DCCLIMIT != [-1]))
  844.         {
  845.             if (PP.SET.DCCQUEUEING == [ON])
  846.             {
  847.                 @ ALREADY = 0
  848.                 foreach DCC.SENDQUEUE AA {
  849.                     if ((word(0 $DCC.SENDQUEUE[$AA]) == [$0])&&(word(2 $DCC.SENDQUEUE[$AA]) == [$2]))
  850.                     {
  851.                         //^notice $0 You already have a request for pack #$strip(# $2) queued
  852.                         @ ALREADY = 1
  853.                     }
  854.                 }
  855.                 if (!ALREADY)
  856.                 {
  857.                     @ DCC.SENDQUEUE[$time()] = [$*]
  858.                     echo *** DCC SEND request for pack #$strip(# $2) to $0 queued: no more slots available
  859.                     //^notice $0 No more DCC slots available: your request has been queued
  860.                 }
  861.                 ^assign -ALREADY
  862.             }
  863.             {
  864.                 //^notice $0 No more DCC slots available
  865.                 echo *** DCC SEND request for pack #$strip(# $2) to $0 denied: no more slots available
  866.             }
  867.         }
  868.         {
  869.             @ PACKNUM = strip(# $2)
  870.             //^notice $0 Sending you pack #$PACKNUM \(you will need $formatnumber($DCCPACKS.SIZE[$PACKNUM])\)
  871.             //^notice $0 Type /dcc get $N <file> for each request received
  872.             @ CTR = 0
  873.  
  874. # increment the number of times this pack has been sent
  875.             @ AA = $DCCPACKS.STATS[$PACKNUM]
  876.             @ AA = AA + 1
  877.             @ DCCPACKS.STATS[$PACKNUM] = AA
  878.             
  879. # iterate over the files in the pack
  880.             while (listitem($CTR $DCCPACKS.FILES[$PACKNUM]))
  881.             {
  882.                 @ AA = listitem($CTR $DCCPACKS.FILES[$PACKNUM])
  883.  
  884.                 //^dcc close send $0 $AA
  885.                 //^dcc send $0 $AA
  886. #                
  887.                 if (PP.SET.DCCTIMEOUT > 0)
  888.                 {
  889.                     ^dcc.queuetimeout $0 $time() $AA
  890.                 }
  891.  
  892.                 @ CTR = CTR + 1
  893.             }
  894.             ^assign -AA
  895.             ^assign -CTR
  896.             echo *** DCC pack #$PACKNUM sent to $0 [$strip( $1)]
  897.             ^assign -PACKNUM
  898.         }
  899.     } 
  900.     {
  901.         //^notice $0 There is no pack #$strip(# $2)
  902.     }
  903. }
  904.  
  905. # ----------------------------------------------------------------------------
  906.  
  907. EVAL ^if (!PP.SET.NOSTARTUP) {/echo -- PurePak file server module loaded}
  908.